from django.contrib.auth.models import User
from django.db import models


# Create your models here.
class Classes(models.Model):
    # id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=30, unique=True)

    # slogan = models.CharField(max_length=50)
    def __str__(self):
        # return 'Class<name=%s>' % self.name
        return self.name


class Label(models.Model):
    name = models.CharField(max_length=30, unique=True)

    def __str__(self):
        return self.name


class UserDetail(models.Model):
    age = models.IntegerField(null=True, blank=True)
    sex = models.BooleanField(null=True, blank=True)
    user = models.OneToOneField(User, on_delete=models.CASCADE)


class Article(models.Model):
    title = models.CharField(max_length=30)
    desc = models.CharField(max_length=100)
    content = models.TextField()
    cover = models.TextField()
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    classes = models.ForeignKey(Classes, on_delete=models.NOT_PROVIDED)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    label = models.ManyToManyField(Label)

    def __str__(self):
        return self.title
